local skel = fk.CreateSkill {
  name = "wish_fulfill_skill",
}

local U = require "packages.utility.utility"

skel:addEffect("cardskill", {
  prompt = "#wish_fulfill_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.CanUseToSelf,
  on_effect = function(self, room, effect)
    local player = effect.to
    local cardType = room:askToChoice(player, { choices =  {"basic", "trick", "equip"}, skill_name = self.name })
    local names, ids = {}, {}
    local max = 3
    -- 优先抽牌堆的，避免捡垃圾一直用
    local piles = table.simpleClone(room.draw_pile)
    -- 牌名权重为此牌名的数量
    while #piles > 0 and #names < max do
      local id = table.remove(piles, math.random(#piles))
      local card = Fk:getCardById(id)
      if card:getTypeString() == cardType and card.name ~= "wish_fulfill" then
        if table.insertIfNeed(names, card.name) then
          table.insert(ids, id)
        end
      end
    end
    if #names < max then
      piles = table.simpleClone(room.discard_pile)
      while #piles > 0 and #names < max do
        local id = table.remove(piles, math.random(#piles))
        local card = Fk:getCardById(id)
        if card:getTypeString() == cardType and card.name ~= "wish_fulfill" then
          if table.insertIfNeed(names, card.name) then
            table.insert(ids, id)
          end
        end
      end
    end
    if #names == 0 then return end
    local name = room:askToChoice(player, {skill_name = skel.name, choices = names})
    --U.askForChooseCardNames(room, player, names, 1, 1, self.name)[1]
    room:moveCardTo(ids[table.indexOf(names, name)], Player.Hand, player, fk.ReasonJustMove, skel.name, nil, false)
  end,
})


Fk:loadTranslationTable{
  ["wish_fulfill_skill"] = "心想事成",
  ["#wish_fulfill_skill"] = "选择一种类型，再从3种此类型的牌挑选一张获得",
}

return skel
